package lesson14.thrift;

import com.alibaba.fastjson.JSON;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.*;

/**
 * <br/>
 * Created on : 2018-06-13 00:50
 * @author lizebin
 */
public class Client {

    public static void main(String[] args) throws Exception {

        //服务端和客户端的传输层和协议层需要对应上
        TTransport transport = new TFramedTransport(new TSocket("localhost", 8899), 600);
        TProtocol protocol = new TCompactProtocol(transport);
        PersonService.Client client = new PersonService.Client(protocol);

        try {
            transport.open();
            System.out.println(JSON.toJSONString(client.getByName("lizebin")));
            Person person = new Person();
            person.setMarried(true);
            person.setName("lizebin");
            person.setAge(27);
            client.save(person);

            System.out.println(JSON.toJSONString(client.getByName("lizebin")));
        } catch (Exception e) {
            throw e;
        } finally {
            if(transport.isOpen()) {
                transport.close();
            }
        }
    }

}
